﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CalculateModelClasses;

namespace RayTracingModel
{
   public class DiffractEfiledCal
    {
        //光速常量
        private const int CSpeed = 300;

        //绕射场强计算公式
        public static Efield DiffractEField(Efield In, RayInfo RayIn, RayInfo RayOut, double s1, double s2, List<Face> faces, Point Porta, Point Portb,double f)
        {
            List<double> paras = GetPara(s1, RayIn, RayOut, faces, Porta, Portb);
            List<double> f0 = new List<double>();
            List<double> fn = new List<double>();
            f0.Add(faces[0].conductivity); f0.Add(faces[0].permittivity);
            fn.Add(faces[1].conductivity); fn.Add(faces[1].permittivity);
            return DiffractEfield(In, RayIn, RayOut, s1, s2, Porta, Portb, paras, f, f0, fn);
        }

        //私有方法
        #region

        //绕射场强计算公式
        private static Efield DiffractEfield(Efield In, RayInfo RayIn, RayInfo RayOut, double s1, double s2, Point Porta, Point Portb, List<double> paras, double f, List<double> f0, List<double> fn)
        {

            Plural X = new Plural();
            X.Re = DiffractHorizonE(In, RayIn, RayOut, s1, s2, Porta, Portb, paras, f, f0, fn).X.Re + DiffractVerticalE(In, RayIn, RayOut, s1, s2, Porta, Portb, paras, f, f0, fn).X.Re;
            X.Im = DiffractHorizonE(In, RayIn, RayOut, s1, s2, Porta, Portb, paras, f, f0, fn).X.Im + DiffractVerticalE(In, RayIn, RayOut, s1, s2, Porta, Portb, paras, f, f0, fn).X.Im;
            Plural Y = new Plural();
            Y.Re = DiffractHorizonE(In, RayIn, RayOut, s1, s2, Porta, Portb, paras, f, f0, fn).Y.Re + DiffractVerticalE(In, RayIn, RayOut, s1, s2, Porta, Portb, paras, f, f0, fn).Y.Re;
            Y.Im = DiffractHorizonE(In, RayIn, RayOut, s1, s2, Porta, Portb, paras, f, f0, fn).Y.Im + DiffractVerticalE(In, RayIn, RayOut, s1, s2, Porta, Portb, paras, f, f0, fn).Y.Im;
            Plural Z = new Plural();
            Z.Re = DiffractHorizonE(In, RayIn, RayOut, s1, s2, Porta, Portb, paras, f, f0, fn).Z.Re + DiffractVerticalE(In, RayIn, RayOut, s1, s2, Porta, Portb, paras, f, f0, fn).Z.Re;
            Z.Im = DiffractHorizonE(In, RayIn, RayOut, s1, s2, Porta, Portb, paras, f, f0, fn).Z.Im + DiffractVerticalE(In, RayIn, RayOut, s1, s2, Porta, Portb, paras, f, f0, fn).Z.Im;
            Efield e = new Efield(X, Y, Z);
            return e;
        }

        //绕射场的水平电场计算
        private static Efield DiffractHorizonE(Efield In, RayInfo RayIn, RayInfo RayOut, double s1, double s2, Point Porta, Point Portb, List<double> paras, double f, List<double> f0, List<double> fn)
        {
            SpectVector l;
            double phase = SpectVector.VectorPhase(RayIn.RayVector, new SpectVector(Porta, Portb));
            if (phase <= 90)
            {
                l = new SpectVector(Porta, Portb);
            }
            else
            {
                l = new SpectVector(Portb, Porta);
            }
            Plural HeIn = Efield.GetHorizonalE(In, RayIn.RayVector, l);
            Plural HD = DiffractParaHorizonal(paras, f, f0, fn);
            Plural A = DspreadPara(s1, s2);
            Plural HE = HeIn * HD * A * GetPhase(s2, f);
            SpectVector l1 = SpectVector.VectorCrossMultiply(RayOut.RayVector, l);
            SpectVector l2 = SpectVector.VectorCrossMultiply(RayOut.RayVector, l1);
            Efield DiffHE = SpectVector.VectorDotMultiply(HE, l2);
            return DiffHE;
        }

        //绕射场的垂直电场计算
        private static Efield DiffractVerticalE(Efield In, RayInfo RayIn, RayInfo RayOut, double s1, double s2, Point Porta, Point Portb, List<double> paras, double f, List<double> f0, List<double> fn)
        {
            SpectVector l;
            double phase = SpectVector.VectorPhase(RayIn.RayVector, new SpectVector(Porta, Portb));
            if (phase <= 90)
            {
                l = new SpectVector(Porta, Portb);
            }
            else
            {
                l = new SpectVector(Portb, Porta);
            }
            Plural VeIn = Efield.GetVerticalE(In, RayIn.RayVector, l);
            Plural VD = DiffractParaVertical(paras, f, f0, fn);
            Plural A = DspreadPara(s1, s2);
            Plural VE = VeIn * VD * A * GetPhase(s2, f);
            SpectVector n = SpectVector.VectorCrossMultiply(RayOut.RayVector, l);
            Efield DiffVE = SpectVector.VectorDotMultiply(VE, n);
            return DiffVE;
        }

        //获得相位
        private static Plural GetPhase(double s2, double f)
        {
            double WaveLength = CSpeed / f;
            double k = 2 * Math.PI / WaveLength;
            Plural phase = new Plural(Math.Cos(k * s2), Math.Sin(k * s2));
            return phase;
        }

        //绕射扩散因子计算
        private static Plural DspreadPara(double s1, double s2)
        {
            return new Plural(Math.Sqrt(s1 / (s2 * (s1 + s2))));
        }

        //计算绕射所需的参数，如入射面、绕射面和0面的夹角,参数顺序为L、Φ0、Φn、n。
        private static List<double> GetPara(double s1, RayInfo RayIn, RayInfo RayOut, List<Face> faces, Point Porta, Point Portb)
        {
            List<double> paras = new List<double>();
            if (Face.CommonPoints(faces[0], faces[1]).Count != 2)
            {
                return paras;
                throw new Exception("该两个面不是绕射面");
            }
            double RayInAngle=SpectVector.VectorPhase(RayIn.RayVector,new SpectVector(Porta,Portb));
            if(RayInAngle>90)RayInAngle=180-RayInAngle;
            //计算L的值
            double L=s1*Math.Pow(Math.Sin(RayInAngle*Math.PI/180),2);
            paras.Add(L);
            //计算两个面的夹角，求得n
            double n, FaceAngle,angle0,anglen;//a0为入射面与0面夹角，an为绕射面与0面夹角
            faces[0]=new Face(Intersection.Find(Porta,Portb,faces[0]),Porta,Portb);faces[1]=new Face(Intersection.Find(Porta,Portb,faces[1]),Porta,Portb);
            //凹面
            try
            {
                if (Intersection.Iscontex(Porta, Portb, RayIn.origin, faces) == false)
                {
                    FaceAngle = 360 - SpectVector.VectorPhase(faces[0].GetVeticalVector(), faces[1].GetVeticalVector());
                    angle0 = SpectVector.VectorPhase(new Face(RayIn.origin, Porta, Portb).GetVeticalVector(), faces[0].GetVeticalVector());
                    Point OutPoint = new Point(RayOut.origin.x + RayOut.RayVector.a, RayOut.origin.y + RayOut.RayVector.b, RayOut.origin.z + RayOut.RayVector.c);
                    anglen = SpectVector.VectorPhase(new Face(OutPoint, Porta, Portb).GetVeticalVector(), faces[0].GetVeticalVector());
                }
                //凸面
                else
                {
                    FaceAngle = SpectVector.VectorPhase(faces[0].GetVeticalVector(), faces[1].GetVeticalVector());
                    if (Intersection.IsOutFace(faces[0], RayIn.origin) == Intersection.IsOutFace(faces[0], Intersection.Find(Porta, Portb, faces[1])))
                    {
                        angle0 = 360 - SpectVector.VectorPhase(new Face(RayIn.origin, Porta, Portb).GetVeticalVector(), faces[0].GetVeticalVector());
                    }
                    else angle0 = SpectVector.VectorPhase(new Face(RayIn.origin, Porta, Portb).GetVeticalVector(), faces[0].GetVeticalVector());
                    Point OutPoint = new Point(RayOut.origin.x + RayOut.RayVector.a, RayOut.origin.y + RayOut.RayVector.b, RayOut.origin.z + RayOut.RayVector.c);
                    if (Intersection.IsOutFace(faces[0], OutPoint) == Intersection.IsOutFace(faces[0], Intersection.Find(Porta, Portb, faces[1])))
                    {
                        anglen = 360 - SpectVector.VectorPhase(new Face(OutPoint, Porta, Portb).GetVeticalVector(), faces[0].GetVeticalVector());
                    }
                    else anglen = SpectVector.VectorPhase(new Face(OutPoint, Porta, Portb).GetVeticalVector(), faces[0].GetVeticalVector());
                }
                n = 2 - FaceAngle / 180;
                paras.Add(angle0); paras.Add(anglen); paras.Add(n);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            return paras;
        }

        //F函数
        private static Plural GetFFunciton(double para)
        {
            Plural F = new Plural();
            if (para > 0.1)
            {
                double re = Math.Sqrt(2 * Math.PI * para) * f(para);
                double im = Math.Sqrt(2 * Math.PI * para) * g(para);
                F.Re = re;
                F.Im = im;
            }
            else
            {
                Plural temp1 = new Plural(Math.Cos(Math.PI / 4), Math.Sin(Math.PI / 4));
                Plural temp2 = new Plural(Math.Cos(Math.PI / 4), -Math.Sin(Math.PI / 4));
                Plural temp3 = new Plural(Math.Cos(Math.PI / 4 + para), Math.Sin(Math.PI / 4 + para));
                F.Re = Math.Sqrt(Math.PI * para) - temp1.Re * 2 * para - 2 * Math.Pow(para, 2) * temp2.Re / 3;
                F.Im = -temp1.Im * 2 * para - 2 * Math.Pow(para, 2) * temp2.Im / 3;
                F = F * temp3;
            }
            return F;
        }

        //求a的方法,注意phi,phi1均为弧度制的
        private static List<double> Geta(double phi, double phi1, double n) 
        {
            
                List<double> a = new List<double>();
                try
                {
                if ((phi >= 0) && (phi <= n * Math.PI) && (n >= 1) && (n <= 2))
                {
                    double beta = phi - phi1;
                    double beta1 = phi + phi1;
                    int N = Convert.ToInt32(Math.Floor((beta - Math.PI) / (2 * Math.PI * n)));
                    double a1 = Math.Cos(2 * n * Math.PI * N - beta) + 1;
                    a.Add(a1);
                    int N1 = Convert.ToInt32(Math.Floor((beta + Math.PI) / (2 * Math.PI * n)));
                    a1 = Math.Cos(2 * n * Math.PI * N1 + beta) + 1;
                    a.Add(a1);
                    N = Convert.ToInt32(Math.Floor((beta1 - Math.PI) / (2 * Math.PI * n)));
                    a1 = Math.Cos(2 * n * Math.PI * N - beta1) + 1;
                    a.Add(a1);
                    N1 = Convert.ToInt32(Math.Floor((beta1 + Math.PI) / (2 * Math.PI * n)));
                    a1 = Math.Cos(2 * n * Math.PI * N1 + beta1) + 1;
                    a.Add(a1);
                   
                }
                else
                {
                    throw new Exception("输入的参数越界！");

                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                
            }
            return a;
        }

        //f和g函数
        private static double f(double x)
        {
            double temp=Math.Sqrt(2*x/Math.PI);
            return (1 + 0.926 * temp) / (2 + 1.792 * temp + 3.104 * Math.Pow(temp, 2));
        }
        private static double g(double x)
        {
            double temp = Math.Sqrt(2 * x / Math.PI);
            return 1 / (2 + 4.142 * temp + 3.492 * Math.Pow(temp, 2) + 6.670 * Math.Pow(temp, 3));
        }

        //垂直绕射系数，f0为0面的介电常数，fn是n面的介电常数,f[0]是conduct，f[1]是相对介电常数
        private static Plural DiffractParaVertical(List<double> paras, double f, List<double> f0, List<double> fn)
        {
            double k = 2 * Math.PI * f / CSpeed;
            Plural DVertical = new Plural();
            double temp = 2 * paras[3] * Math.Sqrt(2 * Math.PI * k);
            Plural temp1 = new Plural(-Math.Cos(Math.PI / 4) / temp, Math.Sin(Math.PI / 4) / temp);
            List<Plural> Gama = GamaVerticalPara(paras, f, f0, fn);
            List<double> CotValue = GetCotValue(paras);
            List<double> a = Geta(paras[1]*Math.PI/180,paras[2]*Math.PI/180,paras[3]);
            Plural item1 = Gama[0] * GetFFunciton(k * paras[0] * a[0]); item1.Re *= CotValue[0]; item1.Im *= CotValue[0];
            Plural item2 = Gama[1] * GetFFunciton(k * paras[0] * a[1]); item2.Re *= CotValue[1]; item2.Im *= CotValue[1];
            Plural item3 = Gama[2] * GetFFunciton(k * paras[0] * a[2]); item3.Re *= CotValue[2]; item3.Im *= CotValue[2];
            Plural item4 = Gama[3] * GetFFunciton(k * paras[0] * a[3]); item4.Re *= CotValue[3]; item4.Im *= CotValue[3];
            Plural TotalItems = item1 + item2 + item3 + item4;
            DVertical = temp1 * TotalItems;
            return DVertical;
        }

        //水平绕射系数，f0为0面的介电常数，fn是n面的介电常数，f[0]是conduct，f[1]是相对介电常数
        private static Plural DiffractParaHorizonal(List<double> paras, double f, List<double> f0, List<double> fn)
        {
            double k = 2 * Math.PI * f / CSpeed;
            Plural DVertical = new Plural();
            double temp = 2 * paras[3] * Math.Sqrt(2 * Math.PI * k);
            Plural temp1 = new Plural(-Math.Cos(Math.PI / 4) / temp, Math.Sin(Math.PI / 4) / temp);
            List<Plural> Gama = GamaHorizionPara(paras, f, f0, fn);
            List<double> CotValue = GetCotValue(paras);
            List<double> a = Geta(paras[1] * Math.PI / 180, paras[2] * Math.PI / 180, paras[3]);
            Plural item1 = Gama[0] * GetFFunciton(k * paras[0] * a[0]); item1.Re *= CotValue[0]; item1.Im *= CotValue[0];
            Plural item2 = Gama[1] * GetFFunciton(k * paras[0] * a[1]); item2.Re *= CotValue[1]; item2.Im *= CotValue[1];
            Plural item3 = Gama[2] * GetFFunciton(k * paras[0] * a[2]); item3.Re *= CotValue[2]; item3.Im *= CotValue[2];
            Plural item4 = Gama[3] * GetFFunciton(k * paras[0] * a[3]); item4.Re *= CotValue[3]; item4.Im *= CotValue[3];
            Plural TotalItems = item1 + item2 + item3 + item4;
            DVertical = temp1 * TotalItems;
            return DVertical;
        }

        //获取Cot值
        private static List<double> GetCotValue(List<double> paras)
        {
            List<double> Cot = new List<double>();
            try
            {
                double plus = paras[1] * Math.PI / 180 + paras[2] * Math.PI / 180;
                double deduct = paras[1] * Math.PI / 180 - paras[2] * Math.PI / 180;
                double temp1 = (Math.PI - deduct) / 2 / paras[3]; double temp2 = (Math.PI + deduct) / 2 / paras[3];
                double temp3 = (Math.PI - plus) / 2 / paras[3]; double temp4 = (Math.PI + plus) / 2 / paras[3];
                Cot.Add(Math.Cos(temp1) / Math.Sin(temp1));
                Cot.Add(Math.Cos(temp2) / Math.Sin(temp2));
                Cot.Add(Math.Cos(temp3) / Math.Sin(temp3));
                Cot.Add(Math.Cos(temp4) / Math.Sin(temp4));
            }
            catch (Exception e)
            {
                return new List<double>();
                throw new Exception(e.Message);               
            }
            return Cot;
        }

        // 计算垂直极化Gama分量(F0是0面：FO[0]是Conduct,FO[1]是Epara；Fn是n面：Fn[0]是Conduct，Fn[1]是Epara)

        private static List<Plural> GamaVerticalPara(List<double> para, double f, List<double> F0, List<double> Fn)
        {
            //Plural 
            List<Plural> gama = new List<Plural>();
            //ReflectEfieldCal reflect = new ReflectEfieldCal();
            // jiezhi JZ=new jiezhi();

            if (para[1] <= Math.PI * 0.5 * para[3] && para[2] <= Math.PI * 0.5 * para[3] && para[1] > para[2])
            {
                //gama[0] = 1;
                //gama.Add(1);
                Plural P1 = new Plural();
                P1.Re = 1;
                P1.Im = 0;
                gama.Add(P1);//gama1
                gama.Add(P1);//gama2
                gama.Add(ReflectEfieldCal.VerticalReflectance(para[2], F0[0], f, F0[1]));//0方向反射系数的垂直分量gama3
                gama.Add(ReflectEfieldCal.VerticalReflectance(para[1], Fn[0], f, Fn[1]));//n方向反射系数的垂直分量gama4
                return gama;
            }
            else if (para[1] <= Math.PI * 0.5 * para[3] && para[2] <= Math.PI * 0.5 * para[3] && para[1] < para[2])
            {
                Plural P1 = new Plural();
                P1.Re = 1;
                P1.Im = 0;
                gama.Add(P1);//gama1
                gama.Add(P1);//gama2
                gama.Add(ReflectEfieldCal.VerticalReflectance(para[1], F0[0], f, F0[1]));//0方向反射系数的垂直分量gama3
                gama.Add(ReflectEfieldCal.VerticalReflectance(para[2], Fn[0], f, Fn[1]));//n方向反射系数的垂直分量gama4
                return gama;
            }
            else if (para[2] <= Math.PI * 0.5 * para[3] && para[1] > Math.PI * 0.5 * para[3])
            {
                Plural P1 = new Plural();
                P1.Re = 1;
                P1.Im = 0;
                gama.Add(P1);//gama1
                Plural P3 = ReflectEfieldCal.VerticalReflectance(para[2], F0[0], f, F0[1]);//0方向反射系数的垂直分量
                Plural P4 = ReflectEfieldCal.VerticalReflectance(Math.PI * para[3] - para[1], Fn[0], f, Fn[1]);//n方向反射系数的垂直分量
                gama.Add(P3 * P4);//0方向反射系数的垂直分量gama2
                gama.Add(ReflectEfieldCal.VerticalReflectance(para[2], F0[0], f, F0[1]));//0方向反射系数的垂直分量gama3
                gama.Add(ReflectEfieldCal.VerticalReflectance(para[3] * Math.PI - para[1], Fn[0], f, Fn[1]));//n方向反射系数的垂直分量gama4
                return gama;
            }
            else if (para[2] > para[3] * Math.PI * 0.5 && para[1] <= para[3] * Math.PI * 0.5)
            {
                Plural P2 = ReflectEfieldCal.VerticalReflectance(para[1], F0[0], f, F0[1]);
                Plural P3 = ReflectEfieldCal.VerticalReflectance(para[3] * Math.PI - para[2], Fn[0], f, Fn[1]);
                gama.Add(P2 * P3);//反射系数的垂直分量gama1
                Plural P1 = new Plural();
                P1.Re = 1;
                P1.Im = 0;
                gama.Add(P1);//gama2
                gama.Add(P2);//0方向反射系数的垂直分量gama3
                gama.Add(P3);//n方向反射系数的垂直分量gama4
                return gama;
                //Plural P0=P1+P3;


            }
            else if (para[1] > 0.5 * Math.PI * para[3] && para[2] > 0.5 * Math.PI * para[3] && para[2] < para[1])
            {
                Plural P1 = new Plural();
                P1.Re = 1;
                P1.Im = 0;
                gama.Add(P1);//gama1
                gama.Add(P1);//gama2
                gama.Add(ReflectEfieldCal.VerticalReflectance(para[3] * Math.PI - para[2], F0[0], f, F0[1]));//0方向反射系数的垂直分量gama3
                gama.Add(ReflectEfieldCal.VerticalReflectance(para[3] * Math.PI - para[1], Fn[0], f, Fn[1]));//n方向反射系数的垂直分量gama4
                return gama;
            }
            else if (para[1] > 0.5 * Math.PI * para[3] && para[2] > 0.5 * Math.PI * para[3] && para[1] < para[2])
            {
                Plural P1 = new Plural();
                P1.Re = 1;
                P1.Im = 0;
                gama.Add(P1);//gama1
                gama.Add(P1);//gama2
                gama.Add(ReflectEfieldCal.VerticalReflectance(para[3] * Math.PI - para[1], F0[0], f, F0[1]));//0方向反射系数的垂直分量gama3
                gama.Add(ReflectEfieldCal.VerticalReflectance(para[3] * Math.PI - para[2], Fn[0], f, Fn[1]));//n方向反射系数的垂直分量gama4
                return gama;
            }
            else
            {
                throw new Exception("此种情况不在考虑范围内！");
            }
        }
        
        //计算水平极化Gama分量	(F0是0面：FO[0]是Conduct，FO[1]是Epara；Fn是n面：Fn[0]是Conduct，Fn[1]是Epara)

        private static List<Plural> GamaHorizionPara(List<double> para, double f, List<double> F0, List<double> Fn)
        {
            List<Plural> gama = new List<Plural>();
            ReflectEfieldCal reflect = new ReflectEfieldCal();
            //jiezhi JZ = new jiezhi();
            if (para[1] <= Math.PI * 0.5 * para[3] && para[2] <= Math.PI * 0.5 * para[3] && para[1] < para[2])
            {
                //gama[0] = 1;
                //gama.Add(1);
                Plural P1 = new Plural();
                P1.Re = 1;
                P1.Im = 0;
                gama.Add(P1);//gama1
                gama.Add(P1);//gama2
                gama.Add(ReflectEfieldCal.HorizonalReflectance(para[2], F0[0], f, F0[1]));//0方向反射系数的水平分量gama3
                gama.Add(ReflectEfieldCal.HorizonalReflectance(para[1], Fn[0], f, Fn[1]));//n方向反射系数的水平分量gama4
                return gama;
            }
            else if (para[1] <= Math.PI * 0.5 * para[3] && para[2] <= Math.PI * 0.5 * para[3] && para[1] > para[2])
            {
                Plural P1 = new Plural();
                P1.Re = 1;
                P1.Im = 0;
                gama.Add(P1);//gama1
                gama.Add(P1);//gama2
                gama.Add(ReflectEfieldCal.HorizonalReflectance(para[1], F0[0], f, F0[1]));//0方向反射系数的水平分量gama3
                gama.Add(ReflectEfieldCal.HorizonalReflectance(para[2], Fn[0], f, Fn[1]));//n方向反射系数的水平分量gama4
                return gama;
            }
            else if (para[2] <= Math.PI * 0.5 * para[3] && para[1] > Math.PI * 0.5 * para[3])
            {
                Plural P1 = new Plural();
                P1.Re = 1;
                P1.Im = 0;
                gama.Add(P1);//gama1
                Plural P3 = ReflectEfieldCal.HorizonalReflectance(para[2], F0[0], f, F0[1]);//0方向反射系数的水平分量
                Plural P5 = ReflectEfieldCal.HorizonalReflectance(Math.PI * para[3] - para[1], Fn[0], f, Fn[1]);//n方向反射系数的水平分量
                gama.Add(P3 * P5);//0方向反射系数的水平分量gama2
                gama.Add(ReflectEfieldCal.HorizonalReflectance(para[2], F0[0], f, F0[1]));//0方向反射系数的水平分量gama3
                gama.Add(ReflectEfieldCal.HorizonalReflectance(para[3] * Math.PI - para[1], Fn[0], f, Fn[1]));//n方向反射系数的水平分量gama4
                return gama;
            }
            else if (para[2] > para[3] * Math.PI * 0.5 && para[1] <= para[3] * Math.PI * 0.5)
            {
                Plural P3 = ReflectEfieldCal.HorizonalReflectance(para[1], F0[0], f, F0[1]);
                //Plural P4 = ReflectEfieldCal.VerticalReflectance(para[1], JZ.Conduct, JZ.F, JZ.Epara);
                Plural P5 = ReflectEfieldCal.HorizonalReflectance(para[3] * Math.PI - para[2], Fn[0], f, Fn[1]);
                //Plural P6 = reflect.VerticalReflectance(para[3] * Math.PI - para[2], JZ.Conduct, JZ.F, JZ.Epara);
                gama.Add(P3 * P5);//反射系数的水平分量gama1
                Plural P1 = new Plural();
                P1.Re = 1;
                P1.Im = 0;
                gama.Add(P1);//gama2
                gama.Add(P3);//0方向反射系数的水平分量gama3
                gama.Add(P5);//n方向反射系数的水平分量gama4
                return gama;
                //Plural P0=P1+P3;


            }
            else if (para[1] > 0.5 * Math.PI * para[3] && para[2] > 0.5 * Math.PI * para[3] && para[2] < para[1])
            {
                Plural P1 = new Plural();
                P1.Re = 1;
                P1.Im = 0;
                gama.Add(P1);//gama1
                gama.Add(P1);//gama2
                gama.Add(ReflectEfieldCal.HorizonalReflectance(para[3] * Math.PI - para[2], F0[0], f, F0[1]));//0方向反射系数的水平分量gama3
                gama.Add(ReflectEfieldCal.HorizonalReflectance(para[3] * Math.PI - para[1], Fn[0], f, Fn[1]));//n方向反射系数的水平分量gama4
                return gama;
            }
            else if (para[1] > 0.5 * Math.PI * para[3] && para[2] > 0.5 * Math.PI * para[3] && para[1] < para[2])
            {
                Plural P1 = new Plural();
                P1.Re = 1;
                P1.Im = 0;
                gama.Add(P1);//gama1
                gama.Add(P1);//gama2
                gama.Add(ReflectEfieldCal.HorizonalReflectance(para[3] * Math.PI - para[1], F0[0], f, F0[1]));//0方向反射系数的水平分量gama3
                gama.Add(ReflectEfieldCal.HorizonalReflectance(para[3] * Math.PI - para[2], Fn[0], f, Fn[1]));//n方向反射系数的水平分量gama4
                return gama;
            }
            else
            {
                throw new Exception("此种情况不在考虑范围内！");
            }
        }
        #endregion
    }
}
